package com.wang.aopdemo.controller;

import com.wang.aopdemo.annotation.CheckAccountBan;
import com.wang.aopdemo.annotation.CheckMuteBan;
import com.wang.aopdemo.annotation.CheckTrafficBan;
import com.wang.aopdemo.annotation.LogAnnotation;
import com.wang.aopdemo.domain.User;
import com.wang.aopdemo.enums.BanTypeEnum;
import com.wang.aopdemo.service.IUserService;
import lombok.extern.java.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * @author yandong
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private IUserService userService;


    /**
     * 登录
     */
    @LogAnnotation("登录")
    @CheckAccountBan // 检查是否被封号, 封号无法登陆
    @GetMapping("/login")
    public String login(String userId) {
        return "login";
    }

    @LogAnnotation("发布评论")
    @CheckMuteBan // 检查是否被禁言, 禁言无法发布评论
    @GetMapping("/publishComment")
    public String publishComment(String userId) {
        return "comment";
    }

    @LogAnnotation("进入推荐列表")
    @CheckTrafficBan // 检查是否被限流, 限流无法进入推荐列表
    @GetMapping("/enterRecommendList")
    public String enterRecommendList() {
        return "进入推荐列表";
    }


    /**
     * 获取用户信息
     */
    public User getUserInfo(String id) {
        return userService.getUserInfo(id);
    }


    /**
     * 封号
     */
    public void banAccount(@RequestBody User user, String banExpireTime) {
        userService.banAccount(user, banExpireTime);
    }

    /**
     * 禁言
     */
    public void banMute(User user, String banExpireTime) {
        user.setBanType(BanTypeEnum.MUTE);
    }

    /**
     * 限流
     */
    public void banTraffic(User user) {
        user.setBanType(BanTypeEnum.TRAFFIC_LIMIT);
    }


}
